#include "uart_setting.h"
#include "uart_interaction.h"
#include "ui_uart_setting.h"
namespace UartNamespace {
UartSetting::UartSetting(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::UartSetting){
  ui->setupUi(this);
}

void UartSetting::AddAvailableSerialPortsToBox(Uartcore* serial_core) {
  QStringList serial_list = serial_core->UartPortScan();
  for (int i=0; i<serial_list.size(); i++){
    ui->comComboBox->addItem(serial_list[i]);
  }
}

UartSetting::~UartSetting(){
  delete ui;
}

void UartSetting::on_buttonBox_accepted(){
  uart_core_->serial_name_ = ui->comComboBox->currentText();
  uart_core_->baud_rate_ = ui->BandRateLineEdit->text().toInt();
  uart_core_->data_bits_ = ui->bitComboBox->currentText().toInt();
  uart_core_->parity_bits_ = ui->parityComboBox->currentText().toInt();
  uart_core_->stop_bits_ = ui->stopComboBox->currentText().toInt();
  uart_core_->flow_control_ = ui->flowctrComboBox->currentText().toInt();
  qDebug()<< "serial_name_:" <<uart_core_->serial_name_;
  qDebug()<< "baud_rate_:" <<uart_core_->baud_rate_;
  qDebug()<< "data_bits_:" <<uart_core_->data_bits_;
  qDebug()<< "parity_bits_:" <<uart_core_->parity_bits_;
  qDebug()<< "stop_bits_:" <<uart_core_->stop_bits_;
  qDebug()<< "flow_control_:" <<uart_core_->flow_control_;
}
}

